var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var TypedocWebpackPlugin = require('typedoc-webpack-plugin');
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var utils = require('./utils');

var lib = require('../src/lib.ts');

module.exports = function () {   
    return {
        entry: {'lib': lib},

        resolve: {
            extensions: ['.js', '.json', '.ts']
        },

        module: {
            loaders: [{
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015']
                }
            },
            {
                test: /\.ts$/,
                include: /src/,
                exclude: /node_modules/,
                loaders: [                  
                    'awesome-typescript-loader',
                    'angular2-template-loader'
                ],                
            },
            {
                test: /\.html$/,
                loader: 'html'
            },

            {
                test: /\.css$/,
                include: utils.root('src'),
                exclude: utils.root('src', 'assets'),
                loader: 'raw'
            },

            { test: /\.scss$/, exclude: utils.root('src', 'assets'), loader: 'raw!sass' },
            { test: /\.scss$/, include: utils.root('src', 'assets'), loader: ExtractTextPlugin.extract({ fallbackLoader: 'style-loader', loader: 'css!sass' }) },

            { test: /\.(woff|woff2|ttf|eot|svg|map)$/, loader: 'file-loader?name=/assets/[name].[ext]' },
            { test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192&name=/assets/[name].[ext]' }
            ]
        },

        plugins: [
            new webpack.BannerPlugin('Owned by WIT'),         

            new webpack.DllPlugin({
                path: utils.root('src') + '/lib/manifest.json',               
                context: __dirname,
                name: 'lib'                
            })
        ],

        output: {
            path: utils.root('src'),           
            filename: 'lib/lib.js',
            library: 'lib',
        },
    }
};
